package demon1;

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class DishApp {

    public static void main(String[] args) {

        initDish();
        Scanner s=new Scanner(System.in);
        while(true){
            showMenu();
            int num=s.nextInt();
            switch (num){
                case 1:
                    while(true){
                        showDish();
                        int id=s.nextInt();
                        if(id==0){
                            break;
                        }
                        System.out.println("请选择菜品编号"+id);
                        orderPrice.add(listDish.get(id-1));
                        break;
                    }
                    break;
                case 2:
                    System.out.println(getprice());
                    break;
                case 3:
                    System.out.println("请输入要支付的金额");{
                        if(s.nextInt()==getprice()){
                            System.out.println("支付成功");
                        }
                }
            }
        }

    }
    public static void showDish(){
        for (int i = 0; i < listDish.size(); i++) {
            System.out.println(listDish.get(i));
        }
    }

    static List<Dish> listDish=new ArrayList<>();
    static List<Dish> orderPrice=new ArrayList<>();
    public static void initDish(){
        listDish.add(new Dish(20.0,"鱼香肉丝",1));
        listDish.add(new Dish(30.0,"红烧鱼",2));
        listDish.add(new Dish(25.0,"麻辣烫",3));
        listDish.add(new Dish(28.0,"小姑炖蘑菇",4));
        listDish.add(new Dish(80.0,"半烤全羊",5));
    }

    public static int getprice(){
        int sum=0;
        for (int i = 0; i < orderPrice.size(); i++) {

            sum+=orderPrice.get(i).price;
        }
        return sum;
    }
    public static void showMenu(){
        System.out.println("1\t菜单\t");
        System.out.println("2\t.已点菜");
        System.out.println("3\t.买单");
    }
}
